1
|
|
|
import * as winston from "winston"; |
2
|
|
|
import * as popsicle from 'popsicle'; |
3
|
|
|
import * as jwt from 'jsonwebtoken'; |
4
|
|
|
import { AuthResponse } from "./response/AuthResponse"; |
5
|
|
|
import { Token } from "./access-token/Token"; |
6
|
|
|
import * as Csrf from 'csrf'; |
7
|
|
|
|
8
|
|
|
interface Scopes { |
9
|
|
|
Accounting: 'com.intuit.quickbooks.accounting', |
10
|
|
|
Payment: 'com.intuit.quickbooks.payment', |
11
|
|
|
Payroll: 'com.intuit.quickbooks.payroll', |
12
|
|
|
TimeTracking: 'com.intuit.quickbooks.payroll.timetracking', |
13
|
|
|
Benefits: 'com.intuit.quickbooks.payroll.benefits', |
14
|
|
|
Profile: 'profile', |
15
|
|
|
Email: 'email', |
16
|
|
|
Phone: 'phone', |
17
|
|
|
Address: 'address', |
18
|
|
|
OpenId: 'openid', |
19
|
|
|
Intuit_name: 'intuit_name', |
20
|
|
|
} |
21
|
|
|
interface Environment { |
22
|
|
|
sandbox: 'https://sandbox-quickbooks.api.intuit.com/', |
23
|
|
|
production: 'https://quickbooks.api.intuit.com/', |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
export default class OAuthClient { |
27
|
|
|
static cacheId: 'cacheID'; |
28
|
|
|
static authorizeEndpoint: 'https://appcenter.intuit.com/connect/oauth2'; |
29
|
|
|
static tokenEndpoint: 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer'; |
30
|
|
|
static revokeEndpoint: 'https://developer.api.intuit.com/v2/oauth2/tokens/revoke'; |
31
|
|
|
static userinfo_endpoint_production: |
32
|
|
|
'https://accounts.platform.intuit.com/v1/openid_connect/userinfo'; |
33
|
|
|
static userinfo_endpoint_sandbox: |
34
|
|
|
'https://sandbox-accounts.platform.intuit.com/v1/openid_connect/userinfo'; |
35
|
|
|
static migrate_sandbox: 'https://developer-sandbox.api.intuit.com/v2/oauth2/tokens/migrate'; |
36
|
|
|
static migrate_production: 'https://developer.api.intuit.com/v2/oauth2/tokens/migrate'; |
37
|
|
|
static environment: Environment; |
38
|
|
|
static jwks_uri: 'https://oauth.platform.intuit.com/op/v1/jwks'; |
39
|
|
|
static user_agent: string; |
40
|
|
|
static scopes: Scopes; |
41
|
|
|
environment: keyof Environment; |
42
|
|
|
clientId: string; |
43
|
|
|
clientSecret: string; |
44
|
|
|
redirectUri: string; |
45
|
|
|
token: Token; |
46
|
|
|
logging: boolean; |
47
|
|
|
logger: winston.Logger | null; |
48
|
|
|
state: Csrf; |
49
|
|
|
|
50
|
|
|
constructor(params: { |
51
|
|
|
clientId: string, |
52
|
|
|
clientSecret: string, |
53
|
|
|
environment: keyof Environment, |
54
|
|
|
redirectUri: string |
55
|
|
|
}); |
56
|
|
|
getJson(): Record<string, any>; |
57
|
|
|
setToken(opts: { |
58
|
|
|
access_token: string; |
59
|
|
|
refresh_token: string; |
60
|
|
|
token_type: string; |
61
|
|
|
expires_in: number; |
62
|
|
|
x_refresh_token_expires_in: number; |
63
|
|
|
id_token?: string; |
64
|
|
|
createdAt?: number |
65
|
|
|
}): Token; |
66
|
|
|
setAuthorizeURLs(params: { |
67
|
|
|
authorizeEndpoint: string; |
68
|
|
|
tokenEndpoint: string; |
69
|
|
|
revokeEndpoint: string; |
70
|
|
|
userInfoEndpoint: string; |
71
|
|
|
}): this; |
72
|
|
|
authorizeUri(opts: { |
73
|
|
|
scope: Scopes[keyof Scopes][], |
74
|
|
|
state: string |
75
|
|
|
}): string; |
76
|
|
|
createToken(uri: string): Promise<AuthResponse>; |
77
|
|
|
refresh(): Promise<AuthResponse>; |
78
|
|
|
refreshUsingToken(refreshToken: string): Promise<AuthResponse>; |
79
|
|
|
revoke(params?: { access_token: string, refresh_token: string }): Promise<AuthResponse>; |
80
|
|
|
getUserInfo(): Promise<AuthResponse>; |
81
|
|
|
makeApiCall(params: { transport: popsicle.TransportOptions, url: string, method: string, headers: Record<string, string>, body: Record<string, any> }): Promise<AuthResponse>; |
82
|
|
|
validateIdToken(params?: { id_token: string }): Promise<boolean>; |
83
|
|
|
getValidatedIdToken(params?: { id_token: string }): Promise<jwt.JwtPayload>; |
84
|
|
|
getKeyFromJWKsURI(id_token: string, kid: string, request: popsicle.Request): Promise<jwt.JwtPayload>; |
85
|
|
|
getPublicKey(): string; |
86
|
|
|
getTokenRequest(request: popsicle.Request): Promise<AuthResponse>; |
87
|
|
|
validateToken(): boolean; |
88
|
|
|
loadResponse(request: popsicle.Request): Promise<popsicle.Response>; |
89
|
|
|
loadResponseFromJWKsURI(request: popsicle.Request): Promise<popsicle.Response>; |
90
|
|
|
createError(e: Error, authResponse: AuthResponse): Error; |
91
|
|
|
isAccessTokenValid(): boolean; |
92
|
|
|
getToken(): Token; |
93
|
|
|
authHeader(): string; |
94
|
|
|
log(level: keyof winston.config.NpmConfigSetLevels, message: string, messageData: string): void; |
95
|
|
|
} |
96
|
|
|
|